Skip to content

Reimplement UpdateShield, UpdateHunter, UpdateAppleFarmer, UpdateJester and UpdateSlave from gynt's units branch (100%, three with OPENSHC_FUNCTION_VISIBILITY_UNITS on) - #537

Merged
gynt merged 6 commits into
sourcehold:mainfrom
kotijekriv:reimpl/units-A-round12-100
Dec 1, 2026

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Five more Map::Units update functions, from gynt's units branch reimpl/map-units-updatefunctions (his draft #204). UpdateShield and UpdateJester read 100.0% in the default build. UpdateHunter, UpdateAppleFarmer and UpdateSlave read 100.0% with main's function-visibility option on, as UpdatePitchman and UpdateEngineer (#514) and UpdateDairyFarmer (#513) do, and 96.3%, 94.6% and 91.7% in the default build: each has to see some callees' bodies and must not see one (UpdateHunter: two, getResourceCountThatCanBeDeposited and updateBuildingSignpostCounter) that main's /GL list shows it. Their status lines carry the default build's number with the remark main uses for such units. With the option on all five read 100.0%. Each commit cites the commits of gynt's that measured the file and those that only touched its text (8ca7861, 2026-10-27, adds all five files whole; 6565c1b touches only UpdateShield and UpdateSlave), lists our steps on it, and credits him as co-author. All five went through our development branches; Claude Fable 5.2 worked on four of them (not UpdateAppleFarmer), and those commits keep its co-author line. One more commit adds the entries to cmake/function-visibility.txt; cmake/compiler-flags-gl.txt gains five lines, one per unit, in the units' own commits. No header change.

Function Address Before Default build Option on
Units::UpdateShield 0x0053C300 gynt's draft 52.39% (cf15f54) 100.0% 100.0%
Units::UpdateHunter 0x0054F860 gynt's draft 52.15% (9f9546f) 96.3% / 86.9% 100.0%
Units::UpdateAppleFarmer 0x00553AE0 gynt's draft 43.32% (69e0814) 94.6% / 89.6% 100.0%
Units::UpdateJester 0x0056E190 gynt's draft 50.14% (93b5ce0) 100.0% 100.0%
Units::UpdateSlave 0x00571C00 gynt's draft 49.88% (cfa098f) 91.7% / 66.3% 100.0%

Raw / normalised where two numbers stand. "Before" is the status of gynt's last measured commit on each file; his later commits on them (6565c1b on UpdateShield and UpdateSlave only, 8ca7861, 974c32f) were not measured.

Measured.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed: the data resolvers with tools/reimplementation-control/enable_reimplemented_data.py, the function resolver of every .cpp in the build with tools/reimplementation-helper/batch/enable_local_functions.py), and sourcehold's reccmp (a86aceb03) with --resolve-wrapped-calls --ignore-security-cookie. Normalised is main's reccmp_report.py figure, which ignores call and tail-jump targets and resolver addresses.
  • Full builds, both modes (made before the last text edits of the five units; each edit gives the same quick_diff listing, so nothing in them is expected to change): every .cpp of this branch on main 830fbd5 but the 3 in the note under Other PRs, all function and data resolvers on, built once with the option off and once with it on: 3,041 files and 3,059 functions, BUILD_OK and 0 failures each, against main 830fbd5 built the same way (3,036 files, 3,054 functions; its option-on build is the one made for cmake: function-visibility.txt entries for UpdatePriest, UpdatePeasant and UpdateMiller #535, on the same tree).
    • Option on: nothing on main reads differently. The five new functions read 100.0% / 100.0%. Average over all functions of the build, raw: 99.24% on both sides. cmake/function-visibility-units.py makes 25 wrapper units holding 160 source files (155 on main): the five units join the group that holds hasUnitReachedDestination, and no other file changes group.
    • Option off: the only functions of main that read differently are UI::Menu::handleMenuItems (97.9%, 100.0% in main's build) and Constructor_Menu (98.4%, 100.0%). Their code is unchanged: reccmp names the constant 0x11000000 they compare with after whatever of ours lands at that address, here a resolver's initialiser, so they flip with the image layout (in Reimplement UpdatePeasant and UpdateMiller from gynt's units branch, under /GL (100%) #533's builds they flipped the other way). The five read as in the table. Average over all functions of the build, raw: 99.34% here, 99.35% on main.
  • Small build, both modes, of this branch's head: 503 files, 513 functions (every /GL file of main, every .cpp that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of Reimplement UpdateCamel, UpdateLady, UpdateMother and UpdateFireEater from gynt's units branch, under /GL (100%) #515, Reimplement UpdateChild, UpdateWheatFarmer, UpdateCrossbowman, UpdateLadderman, UpdateTunneler and UpdateFireThrower from gynt's units branch, under /GL (100%) #516, Reimplement UpdateArabianArcher and UpdateCrusaderArcher from gynt's units branch, under /GL (100%) #518 and Reimplement UpdatePeasant and UpdateMiller from gynt's units branch, under /GL (100%) #533 and UpdatePriest with their callee closures, UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link in a small build, two callers of standUpIfSeated, and every file of a function-visibility group that touches them), 0 failures in both modes. The five read as in the table, and the fourteen and UpdatePriest read 100.0% / 100.0% in both modes.
  • Text pass, before those builds: quick_diff (the group's callees pasted in front of the unit, resolvers as a real build has them) gives the same listing for each file before and after every edit, the last ones included.
  • Checks: the style checks (the maintainers' review asks and main's style_lint.py): nothing to fix automatically, no errors and 60 notes, all of the kinds below.
  • Not run in game.

What got them to 100%

The text started from his drafts; each commit lists what changed, with the original's addresses. The last steps, on this main, are:

  • Locals for the slot that went. UpdateJester had them around changeDestinationByAmount and commitUnitLocation, UpdateSlave around changeDestinationByAmount: callees our build sees now, and with the bodies visible the plain DAT_CurrentUnitSlotID::instance reads higher (UpdateJester 0.9612 -> 0.9958 in quick_diff, with its commit; UpdateSlave's went in the same step as the next form, 0.9555 -> 0.9654). UpdateAppleFarmer's spanned a setDestinationForUnit call, which is not among its named callees and stays opaque, so that is no such case: the global everywhere reads 0.9984, with that local kept 0.9891. UpdateHunter's was neutral and went too.
  • The shape of a sibling that is at 100% on main: UpdateShield's capture block is UpdateBatteringRam's (the new owner in a local of its own), UpdateAppleFarmer's waiting state is UpdateDairyFarmer's (the worker store before the frame), UpdateSlave's dig state is UpdatePikeman's (the unit on the tile read once) and the end of its state 0 is UpdateEngineer's three-arm chain. UpdateJester's movementSpeed < 1 and the local for UpdateSlave's moat index were read off the listing.
  • Neither of those: UpdateShield's scan bound read as the global itself instead of through a local (0.9827 -> 0.9859), and UpdateSlave's dig state, whose two frame arms are the other way round; both in their commits.

The option and the entries

  • Why three need it: UpdateHunter and UpdateAppleFarmer read the slot again behind getResourceCountThatCanBeDeposited, UpdateHunter also behind updateBuildingSignpostCounter, and UpdateSlave treats getBuildingFlammabilityFactor as opaque. All three callees are on main's /GL list, so the default build sees their bodies. With the option on, the first two are in wrapper units of their own callers and the third is a /GL file that a unit in a wrapper doesn't see.
  • The entries name only callees that are already members of the group that holds hasUnitReachedDestination (UpdateShield 2, UpdateHunter 10, UpdateJester 8). Main's entries for UpdateAppleFarmer and UpdateSlave, which the generator skipped while the files didn't exist, name two more each (ConsiderHavingABreakNowUnk, UpdateWorker_ConsiderTakingABreakUnk; xyAreValid, changeDestinationByAmount). So five units join that group's wrapper unit, and no other function sees a body it didn't see before or loses one. The commit gives what each named callee reads when left out, and which others were tried.

Kept as they are

  • int dx; / int dy; without a value and two for (; ...) loops (UpdateShield), as in main's UpdateBatteringRam: createTribe reads the scan's counter after the loop (the original passes the owner of units[maxUnitCount], not the new owner; a fixme: says so), and the new owner is used after its search. addUnitToTribe(newTribe, <slot>) there passes the tribe as unitID and the shield as tribeID, as the original does (0x0053C736); a fixme: says so, as in UpdateBatteringRam.
  • (char) on engineerManningSiegeStateRef_checkType (UpdateHunter, UpdateJester, UpdateSlave twice): the field holds the fade step, so the tests read it signed. It is a byte in the header, as in Reimplement UpdateCamel, UpdateLady, UpdateMother and UpdateFireEater from gynt's units branch, under /GL (100%) #515, Reimplement UpdateChild, UpdateWheatFarmer, UpdateCrossbowman, UpdateLadderman, UpdateTunneler and UpdateFireThrower from gynt's units branch, under /GL (100%) #516, Reimplement UpdateArabianArcher and UpdateCrusaderArcher from gynt's units branch, under /GL (100%) #518 and Reimplement UpdatePeasant and UpdateMiller from gynt's units branch, under /GL (100%) #533.
  • (short) stores of the slot, of building, tree and unit indices and of ComputeGoodsProduced's result into short fields, as main's unit functions write them.
  • (int) on the tick sum in UpdateSlave's % 40, as in main's UpdatePikeman: the original divides signed.
  • BOOLEnum calls tested by truthiness, int calls compared with 0 (buildingIsAccessible, updateBuildingSignpostCounter, findNearestShootableDeer, setXYBasedOnMoatID, getBuildingFlammabilityFactor), and the two-byte flags and DAT_UnitHasBecomeIdle (undefined4) compared with 0, as main does. advanceMoatDigProgress and removeMoat are compared with 1 in UpdateSlave, as in UpdatePikeman, with a comment.
  • Arms: UpdateSlave's state 0 ends in two arms that store the same state: the original branches on 400 only (0x00571EFD), and a two-way if / else or an early return for the first arm becomes a setcc. The middle arm is UpdateEngineer's, needed for the listing; 96 is UpdateEngineer's number, by analogy; the original has no 96 here. UpdateHunter's chase repeats its speed arms, each with its own pair of numbers. UpdateJester's two arms store the wandering state; the original has that store once (0x0056E3AF) and so has ours, where the compiler merges the two (one arm for both: 0.9950 and 0.9894 against 0.9986).
  • moat > -1 (UpdateSlave, twice), as in UpdateEngineer: the original compares with -1, and >= 0 loses the match.
  • UpdateHunter's two tests of the substate in one state (USH_WAITING_8: > 1 where it enters, >= 2 where it leaves): made the same, either way, the listing differs (0.9767 and 0.9960 against 0.9991).
  • Loops of one (UpdateShield): the AI check's, and the two that send the engineer to work; written out they read 0.7650, 0.9848 and 0.9913 against 0.9978.
  • UpdateSlave's US_APPEAR stores the sheet offset and the speed in both arms (the original has one sheet store and shares the speed store, at 0x00572134 and 0x0057215B): six hoisted forms lose the match (0.9759 to 0.9782). Its dig state stores the two closing values on both paths (once: 0.9622), as in UpdatePikeman.
  • Truth tests of BOOLEnum / bool fields and locals: animationCycleNumberHasJustIncremented, isMatchingSpeed, and the locals arrowFired (UpdateHunter) and found (UpdateShield). arrowFired and found are not flags in the binary (four tests jump to 0x0054FF45; the loop at 0x0053C6A7 returns at its end), they are the source form that matches.
  • UpdateHunter's states 0 to 11 and 106 carry main's UnitState_Hunter names through state.hunter, and the resting state is USH_RESTING_7, as in UpdatePitchman and UpdateWheatFarmer; 108, 109, 110, 111, 113 and 121, which that enum doesn't name, keep their US_ names.
  • The checker's other notes are Ghidra's placeholder field names (the frame tables below; Unit::field_0x2ac, field_0x32d, field_0x37e, field_0x3bc, field_0x3f4, field_0x58), for which we have nothing better yet. Unit::field_0x58 is a short; the checker's BOOLEnum hint for it comes from another struct.

Differences from the draft

For all five we compared the operators and literals of every test against a number with gynt's drafts; line by line we read only UpdateShield and UpdateSlave. These differ, as the original has it:

  • UpdateShield passes units[searched].owner to createTribe as its owner argument (0x0053C70F), the draft the shield's own owner; and it tests ^ 8 where the draft had ^ 0xfffffff8, the same value under & 15.
  • UpdateSlave's % 40 is a signed remainder (cdq, idiv); the draft's was unsigned.

The rest are the same tests written the other way round with their arms exchanged, BOOLEnum calls tested by truthiness, hex constants in decimal, <= 0 as < 1, > 1 as >= 2, and UpdateSlave's extra > 96 arm, which stores what the arm below it stores.

Names on main these files show (follow-ups, not changed here)

  • UpdateHunter calls BuildingsState::setBuildingToAppleFarm for the hunter's post in his fade state, so that function is not only the apple farm's.

  • The frame tables (UnitPropertiesDefinedData) by the state that reads each; renaming them is a header change, so they stay as they are here:

    Table What it holds
    field_0x3984 / field_0x3a1c / field_0x3a9c / field_0x3b5c hunter idling at his post (substates 0 / 1 / 2 / any other)
    field_0x3c6c / field_0x3c94 hunter in USH_WAITING_8 (substates 0 / 1)
    field_0x3d08 / field_0x3d2c hunter's melee attack / shooting
    field_0x4f40 apple farmer picking apples
    field_0x5ec0 jester juggling, and performing (substate 2)
    field_0x5ee4 / field_0x5f08 / field_0x5f34 jester performing (substates 0 / 1 / 3); field_0x5ee4 is his melee attack too
    field_0x1dd0 / field_0x1df8 slave digging / filling a moat
    field_0x2538 slave setting a building on fire, and his melee attack
    fixme_integerArraySlave5 / fixme_integerArraySlave6 slave in US_STATE_2Unk (odd / even slot)
    field_0x764 / field_0x824 / field_0x7c4 slave's deaths (US_DEATH_01 / US_DEATH_03 / the three stone deaths)

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 6 commits December 1, 2026 17:49
Units::UpdateShield at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the
file: f791380 at 49.29%, cf15f54 at 52.39%, 6565c1b, 8ca7861 (the file again, whole) and the style commit
974c32f), through the forms on our development branches, where its history is (94.0% there, on main 1f87a13).

What the match needed, against the draft:

- The state it starts in is picked by an if / return pair, as in main's UpdateBatteringRam (sub / neg / sbb / and at
  0x0053C382); the draft had a ternary.
- Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone.
- The scan for engineers tests its six conditions as six `if (...) { continue; }` statements, the counts are cleared
  with memset, the distances compare with the engineer first, and the tests read `> 16` and `< 1`, as the original
  compares. The tick test reads `^ 8` where the draft had `^ 0xfffffff8`, the same value under `& 15`.
- The AI check's loop and the two blocks that send the engineer to work are loops of one over manningEngineerRef and
  engineerIDs[9][1]: the first is a loop in the original too (0x0053C4C3), the others make it compute the unit's offset
  anew (0x0053C4D9, 0x0053C744), the start of a loop the compiler unrolled. Written out with index 0 (the first as a do
  / while (0), as its tests break out of it), they read 0.7650, 0.9848 and 0.9913 in quick_diff, against 0.9978.
- The search for the capturing owner is a for loop from 1 to 8 with a found flag, the source form that matches (the
  binary has no flag: the loop at 0x0053C6A7 returns at its end, 0x0053C6B4), and, the last step, it has a local of its
  own that is copied behind the capture, as in main's UpdateBatteringRam, where the parked text searched in the local
  that holds the shield's owner. With it the scan's bound stays in ebx (loaded at 0x0053C57F, compared at 0x0053C682):
  0.9859 -> 0.9978 in quick_diff with the /GL callees in the unit (the one line left, 0xffff against -0x1, is the same
  instruction). The bound read as the global itself instead of through a local came first (0.9827 -> 0.9859).
- createTribe gets the owner of units[searched], where searched is the counter the scan left behind (0x0053C70F); the
  draft passed the shield's own owner. The same call is in main's UpdateBatteringRam, and so is the next one:
  addUnitToTribe gets the tribe as unitID and the shield as tribeID (0x0053C736), with a fixme for each.

compiler-flags-gl.txt gets UpdateShield.cpp only: the two callees it has to see are on main's list already (quick_diff
0.5457 without hasUnitReachedDestination, 0.8707 without deselectUnit, 0.5152 without both).

On main, this round's text pass: main's name for state 108, BOOLEnum calls by truthiness, `++`, `const` on locals, the
fade countdown without its cast, UpdateBatteringRam's names and comments for the scan and its if / return pair for the
first state. The quick_diff listing is the same before and after it.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on
main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp
that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and
UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link
in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them),
once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files,
3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text
edits; quick_diff gives the same listing of every file before and after them. It reads 100.0 / 100.0 in all of them.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…N_VISIBILITY_UNITS on

Units::UpdateHunter, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file:
76bb533 at 48.51%, 9f9546f at 52.15%, 8ca7861 (the file again, whole) and the style commit 974c32f),
through the forms on our development branches, where its history is (95.3% there). 100% with
OPENSHC_FUNCTION_VISIBILITY_UNITS on, with its entry in this branch's last commit; 96.3% in the default build, so the
status line carries that number, as UpdatePitchman's does.

What the match needed, against the draft:

- Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone.
- The states are one if / else-if chain whose arms fall out of it, where the draft had a block per state that returns;
  the shooting state keeps its closing return.
- The shooting state has the "look for another deer, or go home" block once in the arrow part, behind a flag the arrow
  sets, and once behind it (0x0054FF45, 0x0054FF71). The draft had it twice in the arrow part. The flag, arrowFired, is
  the source form that matches: the binary has none, four tests jump to 0x0054FF45.
- The early exits go the original's way round: the other hunter's uid test, "the deer is gone" and "the deer is within
  20" first when chasing, the walk to the post with the failed setDestinationForUnit as the else arm.
- The substate set when the hunter gets back to his post is (mapTimeInTicks & 1) + 2 with no cast (0x00550529), and the
  two height sums of the shot have the terrain height first.

What the option is for: the original knows ten of its callees and treats two, updateBuildingSignpostCounter and
getResourceCountThatCanBeDeposited, as opaque (it reads the slot again behind them). Both are on main's /GL list, so the
default build sees their bodies: quick_diff reads 0.9857 with all /GL callees in the unit, 0.9991 with the ten only,
where the one line left, 0xff against -0x1, is the same instruction. With the option on the two are in other wrapper
units. compiler-flags-gl.txt gets UpdateHunter.cpp, as it has UpdatePitchman.cpp.

On main, this round's text pass: main's names (UnitState_Hunter) for the hunter's states 0 to 11 and 106, through
state.hunter (as main's UpdatePitchman and UpdateWheatFarmer do for theirs), and for the resting state
(USH_RESTING_7); 108 to 111, 113 and 121 keep the shared US_ names; DNE_UNKNOWN_2 and RT_MEAT; BOOLEnum calls by
truthiness, `++` / `--`, `const` on locals, the fade step stored as -2, no `(char)` on the frame tables and the fade
countdown, unused `using` lines dropped, and the local for the slot in front of commitUnitLocation dropped. The
quick_diff listing is the same before and after it.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on
main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp
that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and
UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link
in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them),
once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files,
3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text
edits; quick_diff gives the same listing of every file before and after them. With the option on it reads 100.0 /
100.0, with it off 96.3 / 86.9.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…N_VISIBILITY_UNITS on

Units::UpdateAppleFarmer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file:
69e0814 at 43.32%, 8ca7861 (the file again, whole) and the style commit 974c32f), through the forms on our
development branches, where its history is (94.1% there). 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on, with its
entry as this branch's last commit leaves it; 94.6% in the default build, so the status line carries that number, as
UpdatePitchman's does.

What the match needed, against the draft:

- The branches of four states the original's way round, read off it one basic block at a time: going to the workplace
  and waiting for a tree (the call that works first), the granary walk (its failure path written out), the deposit (one
  local for getResourceCountThatCanBeDeposited's result).
- The last steps: every access reads the unit through DAT_CurrentUnitSlotID::instance (our parked text still indexed
  some through the draft's `unitID` and one state through a local for the slot, across a setDestinationForUnit call,
  which is not a named callee and stays opaque), and the waiting state stores the slot into the orchard's workers[]
  before it reads the frame, as main's UpdateDairyFarmer does. In quick_diff with the group's callees in the unit
  0.9899 -> 0.9984 (the one line left, 0xff against -0x1, is the same instruction). Only together: 0.9844 without the
  second step, 0.9891 with the state's local kept.

What the option is for: the original reads the slot again behind getResourceCountThatCanBeDeposited, which is on main's
/GL list, so the default build sees its body and keeps the register (quick_diff 0.9820 with it, 0.9984 without).
compiler-flags-gl.txt gets UpdateAppleFarmer.cpp, as it has UpdatePitchman.cpp.

On main, this round's text pass: main's names for states 108 and 121 and for DNE_UNKNOWN_2, BOOLEnum calls by
truthiness, `++` / `--`, `const` on locals, no `(char)` on the frame tables and the fade countdown, the unused `using`
lines and one unused include dropped, USAF_WAITING_1 for the resting state and the farmer's own state type for the
local. The quick_diff listing is the same before and after it.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on
main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp
that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and
UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link
in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them),
once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files,
3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text
edits; quick_diff gives the same listing of every file before and after them. With the option on it reads 100.0 /
100.0, with it off 94.6 / 89.6.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateJester at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the
file: 146023d at 42.00%, 93b5ce0 at 50.14%, 8ca7861 (the file again, whole) and the style commit 974c32f),
through the forms on our development branches, where its history is (94.1% there).

What the match needed, against the draft:

- Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone.
- The states are one if / else-if chain whose arms fall out of it, where the draft had a block per state that returns,
  and the first death state tests "the animation is over" first.
- gfxBase is declared at the function's top (with a comment): the original zeroes a register for it in the first block
  and keeps the owner in the frame (0x0056E1C7).
- The random roll is read once into an int local and compared twice (0x0056E336). The text stores the wandering state
  in two arms; the original has the store once (0x0056E3AF) and so has ours, the compiler merges the two arms (one arm
  for both cases loses the match: quick_diff 0.9950 and 0.9894 against 0.9986).
- The last steps, on this main: two locals our parked text had for the slot are gone, one around
  changeDestinationByAmount in the walk-up state and one in front of commitUnitLocation in the fade state. With the
  callees' bodies visible they cost (quick_diff with the /GL callees in the unit 0.9612 -> 0.9936 -> 0.9958). And the
  walk-up state tests `movementSpeed < 1`, a compare with the constant 1 the original holds in bp, where the draft had
  `<= 0`, the same values (0.9958 -> 0.9986; the one line left, 0xff against -0x1, is the same instruction).

compiler-flags-gl.txt gets UpdateJester.cpp only: the eight callees it has to see are on main's list already (quick_diff
without each: checkIfCitizenUnitIsAliveBasedOnState 0.8217, changeDestinationByAmount 0.8870,
hasUnitReachedDestination 0.9627, makeUnitStopWalkingByClearingPathProgressState 0.9859, hasTunnelerNotFinishedDigging
0.9944, commitUnitLocation, setupUnitSharingCurrentTilePosition and setupUnitSharingTileIDs 0.9958 each; 0.5465 without
any).

On main, this round's text pass: main's names for states 2, 3 and 108, BOOLEnum calls by truthiness, `++` / `--`,
`const` on locals, decimal constants, the fade step stored as -2, no `(char)` on the frame tables and the fade
countdown and no `(byte)` on the random number, unused `using` lines and one unused include dropped. The quick_diff
listing is the same before and after it.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on
main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp
that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and
UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link
in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them),
once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files,
3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text
edits; quick_diff gives the same listing of every file before and after them. It reads 100.0 / 100.0 in all of them.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…N_VISIBILITY_UNITS on

Units::UpdateSlave, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file:
1f2f3bf at 43.44%, cfa098f at 49.88%, 6565c1b, 8ca7861 (the file again, whole) and the style commit
974c32f), through the forms on our development branches, where its history is (87.4% there). 100% with
OPENSHC_FUNCTION_VISIBILITY_UNITS on, with its entry as this branch's last commit leaves it; 91.7% in the default
build, so the status line carries that number, as UpdatePitchman's does.

What the match needed, against the draft:

- Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone.
- The fill-moat branch counts the moat's countdown down first, then sets the targeting type, on every path (in the
  source, the path where setXYBasedOnMoatID returns 0 has the two the other way round, as main's UpdateEngineer does;
  the other order loses the match, quick_diff 0.9710 against 0.9792). The moving state tests "delay running" first; its
  moat branch and the digging walk go the original's way round.
- The last steps, on this main (quick_diff with the group's callees in the unit, each on the one before):
  - the parked text's local for the slot across changeDestinationByAmount is gone, the dig state's two frame arms are
    the other way round, and the unit on the dig tile is read once into a local, as in main's UpdatePikeman (0.9555 ->
    0.9654);
  - state 0 ends in a chain of three arms whose last two store the same state, as in main's UpdateEngineer: the
    original branches on 400 only (0x00571EFD), a two-way if / else and an early return for the 400 arm become a setcc
    instead (0.9683), and 0.9654 -> 0.9764 for the chain on the earlier text. The 96 of the middle arm is
    UpdateEngineer's number, by analogy; the original has no 96 here.
  - the moat's owner is read through a local for returnOwnedMoatAtTile's result (0.9764 -> 0.9792).
  What is left of the 0.9792 is how quick_diff spells constants, two-global sums and the timeGetTime import.
- `(int)` on the tick sum in front of `% 40`: the original divides signed (cdq, idiv), as in main's UpdatePikeman; the
  draft's remainder is unsigned, which differs once the sum passes 2^31.

What the option is for: getBuildingFlammabilityFactor is on main's /GL list, so the default build sees its body, and the
original treats it as opaque (quick_diff 0.9284 with it, 0.9792 without).
compiler-flags-gl.txt gets UpdateSlave.cpp, as it has UpdatePitchman.cpp.

On main, this round's text pass: main's names for states 2, 104, 105, 108 and 124 and for CD_UNSPECIFIED and L_MOAT,
BOOLEnum calls by truthiness, `++` / `--`, `const` on locals, no `(char)` on the frame tables and the fade countdown
and no `(short)` where main's UpdatePikeman has none, the string's text above its pointer, one unused include dropped,
CD_SOUTH for the rally's facing, an else-if and one else less around the two returns. The quick_diff listing is the
same before and after it. The compares with -1 (0.9693 with >= 0), the two closing stores of the dig state written on
both paths (0.9622 when written once), and the US_APPEAR stores of the sheet offset and the speed in both arms (0.9759
to 0.9782 hoisted) are measured, with comments in the text.

Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on
main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp
that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and
UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link
in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them),
once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files,
3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text
edits; quick_diff gives the same listing of every file before and after them. With the option on it reads 100.0 /
100.0, with it off 91.7 / 66.3.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, UpdateAppleFarmer, UpdateJester and UpdateSlave

New entries for UpdateShield, UpdateHunter and UpdateJester; UpdateAppleFarmer's and UpdateSlave's, which main had before
the files existed, each name two more callees. All name only callees that are already members of the group that holds
hasUnitReachedDestination, so the five units join that group's wrapper unit and nothing else moves: no other function
sees a body it didn't see before or loses one.

Each caller-callee pair is measured as sourcehold#491's were (quick_diff, the unit's file with the callee files pasted in front of
it, against the unit alone). The callees tried are the group's members that the unit calls directly or through another
member it calls; one is named when leaving it out lowers the ratio, and the named set reads what the whole set reads:

- UpdateShield 0.5152 alone, 0.9978 with its two: without hasUnitReachedDestination 0.5457, deselectUnit 0.8707.
- UpdateHunter 0.4887 alone, 0.9991 with its ten: without IncrementAndOptionalUpdateAVValueRelated 0.6953,
  checkIfCitizenUnitIsAliveBasedOnState 0.9004, hasUnitReachedDestination 0.9201, ComputeGoodsProduced 0.9840,
  SetStateToFreetimeWalking 0.9880, UpdateWorker_ConsiderTakingABreakUnk and ConsiderHavingABreakNowUnk 0.9907 each,
  commitUnitLocation, setupUnitSharingCurrentTilePosition and setupUnitSharingTileIDs 0.9929 each. Not named:
  makeUnitStopWalkingByClearingPathProgressState (no change).
- UpdateAppleFarmer 0.5793 alone, 0.9984 with its seven: without checkIfCitizenUnitIsAliveBasedOnState 0.8558,
  IncrementAndOptionalUpdateAVValueRelated 0.8580, ComputeGoodsProduced 0.8918, hasUnitReachedDestination 0.9408,
  SetStateToFreetimeWalking 0.9891; new in the entry, UpdateWorker_ConsiderTakingABreakUnk and
  ConsiderHavingABreakNowUnk, 0.9713 each. Not named: makeUnitStopWalkingByClearingPathProgressState (no change).
- UpdateJester 0.5465 alone, 0.9986 with its eight: the numbers are in its commit.
- UpdateSlave 0.5410 alone, 0.9792 with its three: without hasUnitReachedDestination 0.5245; new in the entry, xyAreValid
  0.9173 and changeDestinationByAmount 0.9764.

On top of the named callees, each /GL callee outside the group that the unit calls was tried one at a time, without its
own callees: only updateBuildingSignpostCounter (UpdateHunter 0.9933), getResourceCountThatCanBeDeposited (UpdateHunter
0.9915, UpdateAppleFarmer 0.9820) and getBuildingFlammabilityFactor (UpdateSlave 0.9284) change a ratio, and all lower it.

Full build of every file with the option on (3,041 files, 3,059 functions, BUILD_OK, 0 failures), against main
830fbd5's tree built the same way (3,036 files, 3,054 functions): nothing on main reads differently, and the five
units read 100.0 / 100.0. It was made before the last text edits of the five units; quick_diff gives the same listing
of every file before and after them. The generator makes 25 wrapper units holding 160 source files (155 on main): the
five units join the group that holds hasUnitReachedDestination, and no other file changes group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants